//
//  NSString+XML.m
//  TwitterPlane
//
//  Created by kazuyuki takahashi on 10/01/29.
//  Copyright 2010 by invisibledesigner.com. All rights reserved.
//

#import "NSString+XML.h"


@implementation NSString(XMLAdditions)

- (NSString*)stringByUnescapingXMLSpecialChars
{
    NSString *set[] = {
        @"&lt;", @"<", @"&gt;", @">", @"&quot;", @"\"", @"&apos;", @"'", @"&amp;", @"&", nil
    };
    
    NSMutableString *mstr = [[self mutableCopy] autorelease];
    NSRange range = NSMakeRange(0, [mstr length]);
    
    int i = 0;
    while (set[i] != nil) {
        NSUInteger replaced = [mstr replaceOccurrencesOfString:set[i] withString:set[i+1] options:0 range:range];
        range.length -= ([set[i] length] - [set[i+1] length]) * replaced;
        i += 2;
    }

    return mstr;
}

@end
